function message(){
	document.getElementById('brws').innerHTML=
	document.getElementById('dmsg').innerHTML=
	document.getElementById('nick').innerHTML=
	document.getElementById('thst').innerHTML=
	document.getElementById('time').innerHTML=
	document.getElementById('tmsg').innerHTML='';
}
var ctrl=external;
if(!ctrl.AppKey){
	ctrl=new function(){
		this.Agent='(agent)';
		this.AppKey='(appkey)';
		this.Base='(base)';
		this.Token='(token)';
		this.Browse=
		this.SendMessage=
		this.SetMessage=
		this.SetHistory=function(){};
	}
}
var o=document.body;
o.onclick=function(e){
	var t=e?e.target:window.event.srcElement;
	var x=t.innerHTML;
	message();
	switch(t.className){
	case 'brws':
		x=t.toString();
		ctrl.Browse(x);
		document.getElementById('brws').innerHTML=x;
		break;
	case 'msg1':
		document.getElementById('nick').innerHTML=peer;
		document.getElementById('tmsg').innerHTML=x;
		ctrl.SetMessage(peer,x+'\n');
		break;
	case 'msg2':
		document.getElementById('nick').innerHTML=prev;
		document.getElementById('tmsg').innerHTML=x;
		ctrl.SetMessage(prev,x+'\n');
		break;
	case 'hst1':
		document.getElementById('nick').innerHTML=peer;
		document.getElementById('thst').innerHTML=x;
		ctrl.SetHistory(peer,'\n'+x);
		break;
	case 'hst2':
		document.getElementById('nick').innerHTML=prev;
		document.getElementById('thst').innerHTML=x;
		ctrl.SetHistory(prev,'\n'+x);
		break;
	default:
		return true;
	}
	return false;
}
o.ondblclick=function(e){
	var t=e?e.target:window.event.srcElement;
	var x=t.innerHTML;
	message();
	switch(t.className){
	case 'msg1':
	case 'hst1':
		document.getElementById('nick').innerHTML=peer;
		document.getElementById('dmsg').innerHTML=x;
		ctrl.SendMessage(peer,x);
		break;
	case 'msg2':
	case 'hst2':
		document.getElementById('nick').innerHTML=prev;
		document.getElementById('dmsg').innerHTML=x;
		ctrl.SendMessage(prev,x);
	}
}
ctrl.onInfo=function(a,b){
	document.getElementById('info').innerHTML=a;
}
ctrl.onMessage=function(nickname,time,message){
	document.getElementById('mssg').innerHTML=message;
	document.getElementById('nick').innerHTML=nickname;
	document.getElementById('time').innerHTML=time;
	top.location='/inthelp/test?a='+akey+'&k='+tokn+'&s='+encodeURIComponent(agnt)+'&c='+encodeURIComponent(peer)+'&d='+encodeURIComponent(prev)+'&q='+encodeURIComponent(message);
}
ctrl.onSwitch=function(){
	prev=peer;
	peer=ctrl.Peer;
	document.getElementById('peer').innerHTML=peer;
	document.getElementById('prev').innerHTML=prev;
	top.location='/inthelp/test?a='+akey+'&k='+tokn+'&s='+encodeURIComponent(agnt)+'&c='+encodeURIComponent(peer)+'&d='+encodeURIComponent(prev);
}
ctrl.onToken=function(){
	tokn=ctrl.Token;
	document.getElementById('tokn').innerHTML=tokn;
}
var agnt=document.getElementById('prms').innerHTML;
var peer=document.getElementById('prmc').innerHTML;
var prev=document.getElementById('prmd').innerHTML;
var akey=document.getElementById('prma').innerHTML;
var tokn=document.getElementById('prmk').innerHTML;
document.getElementById('agnt').innerHTML=agnt;
document.getElementById('akey').innerHTML=akey;
document.getElementById('tokn').innerHTML=tokn;
document.getElementById('mssg').innerHTML=document.getElementById('prmq').innerHTML;
document.getElementById('peer').innerHTML=peer;
document.getElementById('prev').innerHTML=prev;
document.getElementById('base').innerHTML=ctrl.Base;
